package com.freejava.testactivemq.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Queue;
import javax.jms.Topic;

@RestController
public class MyProducerController {
    // 引入JmsMessageTemplate操作类
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Topic topic;

    @Autowired
    private Queue queue;

    @PostMapping("/topic/send")
    public String sendTopic(@RequestBody String msg) {
        jmsMessagingTemplate.convertAndSend(this.topic, msg);
        return "send a messsge to a topic success!";
    }

    @PostMapping("/queue/send")
    public String sendQueue(@RequestBody String msg) {
        jmsMessagingTemplate.convertAndSend(this.queue, msg);
        return "send a message into a queue success!";
    }
}
